#ifndef ZINGME_NETWORK_CONNECTION_H
#define ZINGME_NETWORK_CONNECTION_H

#include "../networkconnection.h"

#include <QVariant>


class QThread;
namespace Network {
namespace Zingme {
class WebSocket;
class Connection : public Network::Connection
{
    Q_OBJECT
public:
    explicit Connection(QObject *parent = 0);
    virtual ~Connection();

public:
    bool connect(const QString &url, unsigned int port, const QVariant &params);
    bool post(Network::ConnectionRequest *request);
    bool disconnect();

    bool isConnected() const;

signals:
    void connectReady(const QString &url, unsigned int port, const QVariant &params);
    void postReady(Network::ConnectionRequest *request);
    void disconnectReady();

private:
    void onConnected();
    void onReceived(QByteArray message);
    void onDisconnected();

private:
    bool m_disconnecting;
    bool m_connecting;

    QString m_server;
    int m_port;
    QVariant m_params;
    QThread *m_worker;
    WebSocket *m_socket;
};

} // namespace Zingme

} // namespace Network
#endif // ZINGME_NETWORK_CONNECTION_H
